﻿using System;
using System.Security.Cryptography;
using System.Text;
using System.Web.Script.Serialization;

namespace Root.Models.BLL
{
    public class CommonHelper
    {
        public class Json
        {
            private static JavaScriptSerializer JsonSerializer = new JavaScriptSerializer();
            public static string SerializeObject(object _obj)
            {
                return JsonSerializer.Serialize(_obj);
            }

            public static object DeserializeObject(string _json)
            {
                return JsonSerializer.DeserializeObject(_json);
            }
        }
        public class INET
        {
            public static long INET_ATON(string _ip)
            {
                try
                {
                    string[] s = _ip.Split('.');
                    long[] l = new long[s.Length];
                    l[0] = Convert.ToInt64(s[0]);
                    l[1] = Convert.ToInt64(s[1]);
                    l[2] = Convert.ToInt64(s[2]);
                    l[3] = Convert.ToInt64(s[3]);
                    return l[0] * 256 * 256 * 256 + l[1] * 256 * 256 + l[2] * 256 + l[3];
                }
                catch
                {
                    return -1;
                }
            }
        }
        public class Hash
        {
            public static string MD5(string s)
            {
                return BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(s))).Replace("-","");
            }
        }
    }
}